logo Learn HTML
  • Home
  • Tutorials
  • Practice
  • Quiz
  • Projects
  • About
  • Contact

HTML Course

  • HTML HOME
  • HTML Introduction
  • HTML Basic
  • HTML Element
  • HTML Attributes
  • HTML Headings
  • HTML Paragrapha
  • HTML Style
  • HTML Formattin
  • HTML Quotations
  • HTML Colors
  • HTML Css
  • HTML Links
  • HTML Image
  • HTML Favicon
  • Page Tittle
  • HTML Tables
  • HTML Lists
  • Block & Inline
  • HTML Div
  • HTML Classes
  • HTML Id
  • HTML Buttons
  • HTML Iframes
  • HTML File Paths
  • HTML Head
  • HTML Layout
  • HTML Symbols
  • HTML Emojis
  • HTML URL Encode
  • HTML VS XHTML
  • HTML FROM
  • HTML Form
  • Form Attributes
  • Form Elements
  • HTML Input Types
  • HTML Input Attributes
  • Input Form Attributes
  • HTML Graphics
  • HTML Canvas
  • HTML SVG
  • HTML Media
  • HTML Media
  • HTML Video
  • HTML Audio
  • HTML Plug-ins
  • HTML Youtube
  • HTML APIS
  • HTML Web APIS
  • HTML Geolocation
  • HTML Drag & Drop
  • Web Storage
  • Web Workers
  • HTML SSE
  • HTML Examples
  • HTML Examples
  • HTML Editor
  • HTML Quiz
  • HTML Exercises
  • HTML References
  • HTML Tag List
  • HTML Attributes
  • HTML Global Attributes
  • HTML Brower Support
  • HTML Events
  • HTML Colors
  • HTML Canvas
  • HTML Audio & Video
  • HTML Doctypes
  • HTML Character Sets
  • HTML URL Encode
  • Language Codes
  • HTTP Messages
  • HTTP Methods
  • PX to EM Converter
  • keyboard Shortcuts

HTML Form Attributes

HTML forms have special attributes that control how the form behaves when a user submits data.

These attributes are written inside the <form> tag.

The action Attribute

The action attribute tells the browser where to send the form data after the user clicks the submit button.

Usually, the data is sent to a file on the server that processes the information.

Example

<form action="/process.php">
<label for="fname"> First Name: </label> <br/>
<input type="text" id="fname" name="fname" value="john"> <br/>

<label for="lname"> Last Name: </label> <br/>
<input type="text" id="lname" name="lname" value="Doe"> <br/>
</form>

In this example, when the user clicks Submit, the data is sent to process.php.

Important:

If the action attribute is not written, the form data will be sent to the same page.


The target Attribute

The target attribute decides where the response will be displayed after submitting the form.

Common Values:
Value Meaning
_self Opens in the same tab (default)
_blank Opens in a new tab
_parent Opens in the parent frame
_top Opens in the full browser window
iframe name Opens inside a specific iframe

Example (Open in new tab):

<form action="/process.php" target="_blank">

If you do not set the target, the result opens in the same tab.


The method Attribute

The method attribute defines how the form data is sent to the server.

There are two main methods:
  • GET
  • POST

There are two main methods:

Example (Open in new tab):

<form action="/process.php" method="get">

How GET works:

  • Data is added to the URL.
  • Data appears in the browser address bar
  • URL length is limited
  • Can be bookmarked.
Important:

Do NOT use GET for passwords or sensitive information because the data is visible in the URL.

GET is useful for:

  • Search forms
  • Filter forms
  • Non-sensitive data

Method = POST

Example

<form action="/process.php" method="post">

How POST works:

  • Data is sent inside the HTTP request body.
  • Data does NOT appear in the URL.
  • No size limit for large data.
  • Cannot be bookmarked.

POST is recommended for:


  • Login forms
  • Registration forms
  • Personal or sensitive information

Tip: Personal or sensitive information


Try It Your Self

Sign Up For New
Update

HTML Basic
  1. HTML Basic
  2. HTML Element
  3. HTML Attributes
  4. HTML Headings
  5. HTML Paragrapha
  6. HTML Tables
  7. HTML Lists
HTML Advance
  1. HTML Div
  2. HTML Classes
  3. HTML Id
  4. HTML Buttons
  5. HTML Iframes
  6. HTML Symbols
  7. HTML Emojis